package com.asset.dispoal.assetInstitutionBatchParameter.service.commom;

import com.asset.dispoal.assetInstitutionBatchParameter.domain.db.entity.AssetInstitutionBatchParameter;
import com.asset.dispoal.assetInstitutionBatchParameter.domain.db.mapper.AssetInstitutionBatchParameterMapper;
import com.asset.dispoal.assetInstitutionBatchParameter.dto.AssetInstitutionBatchParameterRequest;
import com.asset.dispoal.assetInstitutionBatchParameter.service.converter.AssetInstitutionBatchParameterConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/3/29$
 */
@Component
public class ParameterInsertCommand implements BaseCommand<List<AssetInstitutionBatchParameterRequest>, Result> {


    @Autowired
    AssetInstitutionBatchParameterMapper assetInstitutionBatchParameterMapper;

    @Autowired
    private BaseIdeable<String> idWorker;


    @Override
    public Result execute(List<AssetInstitutionBatchParameterRequest> request) {
        List<AssetInstitutionBatchParameter> assetInstitutionBatchParameter = AssetInstitutionBatchParameterConverter.INSTANCE.reqsToDos(request);
        assetInstitutionBatchParameter.forEach(item -> item.setId(idWorker.generateId()));
        assetInstitutionBatchParameterMapper.saveBatch(assetInstitutionBatchParameter);
        return Result.ok();
    }
}
